#include <iostream>
#include <unordered_map>
#include <stdexcept>

using namespace std;

int wordToNumber(const string& word) {
    static const unordered_map<string, int> wordMap = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    if (wordMap.count(word) == 0) {
        throw invalid_argument("Invalid word: " + word);
    }

    return wordMap.at(word);
}

bool isPrime(int num) {
    if (num <= 1) return false;
    if (num <= 3) return true;
    if (num % 2 == 0 || num % 3 == 0) return false;

    for (int i = 5; i * i <= num; i += 6) {
        if (num % i == 0 || num % (i + 2) == 0) return false;
    }

    return true;
}

int main() 
    {
    string word1, word2, word3;
    cin >> word1 >> word2 >> word3;
    try {
        int num1 = wordToNumber(word1);
        int num2 = wordToNumber(word2);
        int num3 = wordToNumber(word3);

        int number = num1 * 100 + num2 * 10 + num3;

        if (number < 100 || number > 999) {
            throw invalid_argument("Input number is not three-digit");
        }

        int closestPrime = number;
        while (!isPrime(closestPrime)) closestPrime--;

        cout << closestPrime << endl;
    } catch (const exception& e) {
        cerr << e.what() << endl;
    }

    return 0;
}